import java.util.Arrays;
import java.util.Comparator;
import java.util.Scanner;
class PersonSortable2 {
	private String name;
	private int age;
	public PersonSortable2(String name, int age) {
		super();
		this.name = name;
		this.age = age;
	}
	
	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public int getAge() {
		return age;
	}

	public void setAge(int age) {
		this.age = age;
	}

	@Override
	public String toString() {
		return String.format("%s-%d", name,age);
	}
}
/*class NameComparator implements Comparator<PersonSortable2>{
	public int compare(PersonSortable2 o1, PersonSortable2 o2) {
		return o1.getName().compareTo(o2.getName());
	}
}
 class AgeComparator implements Comparator<PersonSortable2>{
	public int compare(PersonSortable2 o1, PersonSortable2 o2) {
		return Integer.toString(o1.getAge()).compareTo(Integer.toString(o2.getAge()));
	}
}
*/
public class Comparator_pta452 {

	public static void main(String[] args) {
		Scanner in=new Scanner(System.in);
		PersonSortable2[] str=new PersonSortable2[in.nextInt()];
		for (int i = 0; i < str.length; i++) {
			str[i]=new PersonSortable2(in.next(), in.nextInt());
		}
		Arrays.sort(str, new Comparator<PersonSortable2>(){
			public int compare(PersonSortable2 o1, PersonSortable2 o2) {
				return o1.getName().compareTo(o2.getName());
			}
		});
		System.out.println("NameComparator:sort");
		for (int i = 0; i < str.length; i++) {
			System.out.println(str[i]);
		}
		Arrays.sort(str, new Comparator<PersonSortable2>(){
			public int compare(PersonSortable2 o1, PersonSortable2 o2) {
				return Integer.toString(o1.getAge()).compareTo(Integer.toString(o2.getAge()));
			}
		});
		System.out.println("AgeComparator:sort");
		for (int i = 0; i < str.length; i++) {
			System.out.println(str[i]);
		}
		System.out.println(this.getClass().getInterfaces());
		//System.out.println(Arrays.toString(Comparator.class.getInterfaces()));
		in.close();
	}
/*	static class NameComparator implements Comparator<PersonSortable2>{
		public int compare(PersonSortable2 o1, PersonSortable2 o2) {
			return o1.getName().compareTo(o2.getName());
		}
	}
    static class AgeComparator implements Comparator<PersonSortable2>{
		public int compare(PersonSortable2 o1, PersonSortable2 o2) {
			return Integer.toString(o1.getAge()).compareTo(Integer.toString(o2.getAge()));
		}
	}
	*/

	
}
